﻿using System;
using System.Collections.Generic;
using ValidationFramework.Web.MVC.JQueryClientScriptProviders;

namespace ValidationFramework.Web.MVC
{
	public static class ClientScriptProviders
	{
		private static readonly IDictionary<Type, IClientScriptProvider> registeredProviders;

		public static IClientScriptProvider GetProvider(Type modelType)
		{
			if (modelType == null)
			{
				throw new ArgumentNullException("modelType");
			}
			IClientScriptProvider provider;
			if (registeredProviders.TryGetValue(modelType, out provider))
			{
				return provider;
			}
			return null;
		}
		public static IDictionary<Type, IClientScriptProvider> ScriptProviders
		{
			get
			{
				return registeredProviders;
			}
		}
		static ClientScriptProviders()
		{
			// set default providers
			registeredProviders = new Dictionary<Type, IClientScriptProvider>
			                       {
			                           {typeof (RequiredStringRule), new JQueryRequiredStringProvider()}
			                       };
		}
	}
}
